In [1]:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from scipy.signal import medfilt, triang
import gitInformation
In [2]:
%matplotlib inline
In [3]:
gitInformation.printInformation()
In [26]:
# Generating data
tri = np.array([0, 1, 2, 3, 4, 5, 4, 3, 2, 1,0])
tri2 = np.array([1, 2, 3, 4, 5, 4, 3, 2, 1, 0])
tri = tri/5.
tri2 = tri2/5.
points = np.array([30, 32, 35, 27, 25, 39, 23, 56])
# Calculate the cumulative sum of the elements
points = np.cumsum(points)
In [27]:
plt.plot(tri)
Out[27]:
In [13]:
x = np.zeros(30)
data = np.append(tri,x)
for i in points:
x = np.zeros(i)
data = np.append(data,tri2)
data = np.append(data,x)
In [14]:
plt.figure(figsize=(30,7))
plt.plot(data)
Out[14]:
In [20]:
noise = np.random.normal(0,0.1, len(data))
noised_data = noise + data
In [21]:
plt.figure(figsize=(30,7))
plt.plot(noised_data)
Out[21]:
In [22]:
wl = np.array([3, 5, 7, 9, 11, 15, 21, 25, 31, 35, 41, 45, 51])
In [23]:
filtered = np.zeros((len(data), len(wl)))
count = -1
for w in wl:
count = count + 1
filtered[:,count] = medfilt(noised_data, w)
In [25]:
pp = PdfPages('noised spike train.pdf')
count = -1
for p in wl:
count = count + 1
fig = plt.figure(count, figsize=(30,7))
plt.plot(noised_data, color = 'cornflowerblue')
plt.plot(data-filtered[:,count], color = 'r', lw = 0.5)
plt.plot(filtered[:,count], color = 'g', lw = 1.5)
plt.xlabel('Window length ' + str(p), fontsize=25)
pp.savefig(fig)
pp.close()